package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.core.domain.model.ReqStringParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.mall.MallOrder;
import com.tencreat.domain.mall.vo.ResIntegralMallOrderVO;
import com.tencreat.service.mall.IIntegralMallOrderService;
import com.tencreat.service.mall.IMallOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 积分订单Controller
 *
 * @author tencreat
 * @date 2021-08-15
 */
@Api(tags="积分订单api")
//@RestController
@RequestMapping("/integral/order")
@ApiIgnore
@Deprecated
public class AdminIntegralMallOrderController extends BaseController {
    //@Autowired
    private IMallOrderService mallOrderService;

    //@Autowired
    private IIntegralMallOrderService iIntegralMallOrderService;

    /**
     * 查询订单列表
     */
    @ApiOperation(value="查询健康币订单列表")
    @PreAuthorize("@ss.hasPermi('mall:order:list')")
    @PostMapping("/list")
    public HttpResult<IPage<MallOrder>> list(@RequestBody  MallOrder mallOrder) {
        QueryWrapper<MallOrder> wrapper = Wrappers.query(mallOrder);
        Page<MallOrder> page =  new Page<>(mallOrder.getPageNum(), mallOrder.getPageSize());
        return HttpResult.ok(mallOrderService.page(page, wrapper));
    }

    /**
     * 查询健康币订单分页列表
     */
    @ApiOperation(value="查询健康币订单分页列表")
    @PreAuthorize("@ss.hasPermi('mall:integral_order:page')")
    @PostMapping("/page")
    public HttpResult<IPage<ResIntegralMallOrderVO>> page(@RequestBody ReqStringParam param) {
        return HttpResult.ok(iIntegralMallOrderService.selectIntegralPage(param));
    }

    /**
     * 导出订单列表
     */
    @ApiOperation(value="导出订单列表")
    @PreAuthorize("@ss.hasPermi('mall:order:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MallOrder mallOrder) {
        List<MallOrder> list = mallOrderService.selectMallOrderList(mallOrder);
        ExcelUtil<MallOrder> util = new ExcelUtil<MallOrder>(MallOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 获取订单详细信息
     */
    @ApiOperation(value="获取订单详细信息")
    @PreAuthorize("@ss.hasPermi('mall:order:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<MallOrder> getInfo(@RequestBody   ReqIdParam id) {
        return HttpResult.ok(mallOrderService.selectMallOrderById(id));
    }

    /**
     * 新增订单
     */
    @ApiOperation(value="新增订单")
    @PreAuthorize("@ss.hasPermi('mall:order:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  MallOrder mallOrder) {
        return to(mallOrderService.insertMallOrder(mallOrder));
    }

    /**
     * 修改订单
     */
    @ApiOperation(value="修改订单")
    @PreAuthorize("@ss.hasPermi('mall:order:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  MallOrder mallOrder) {
        return to(mallOrderService.updateMallOrder(mallOrder));
    }

    /**
     * 删除订单
     */
    @ApiOperation(value="删除订单")
    @PreAuthorize("@ss.hasPermi('mall:order:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody  ReqIdsParam ids) {
        return to(mallOrderService.deleteMallOrderByIds(ids));
    }
}
